//
//  BottomLine.swift
//  Risk_iPhone
//
//  Created by ios on 2020/4/16.
//  Copyright © 2020 ios. All rights reserved.
//

import UIKit
import Foundation

class BottomLineBtn: UIButton {
    
    var lineColor: UIColor = UIColor.white{
        didSet{
            self.setNeedsDisplay()
        }
    }
   
    override func draw(_ rect: CGRect) {
        let textRect: CGRect = self.titleLabel!.frame
        let contextRef: CGContext = UIGraphicsGetCurrentContext()!
        let descender: CGFloat = self.titleLabel!.font.descender
        contextRef.setStrokeColor(lineColor.cgColor)
        contextRef.move(to: CGPoint(x: textRect.origin.x, y: textRect.origin.y + textRect.size.height + descender + 2))
        contextRef.addLine(to: CGPoint(x: textRect.origin.x + textRect.size.width, y: textRect.origin.y + textRect.size.height + descender + 2))
        contextRef.closePath()
        contextRef.strokePath()
    }
    
}


class BottomLineLabel: UILabel {
    
    var lineColor: UIColor = .white{
        didSet{
            self.setNeedsDisplay()
        }
    }
    
    override func draw(_ rect: CGRect) {
        let textRect: CGRect = self.frame
        let contextRef: CGContext = UIGraphicsGetCurrentContext()!
        let descender: CGFloat = self.font.descender
        contextRef.setStrokeColor(lineColor.cgColor)
        contextRef.move(to: CGPoint(x: textRect.origin.x, y: textRect.origin.y + textRect.size.height + descender + 2))
        contextRef.addLine(to: CGPoint(x: textRect.origin.x + textRect.size.width, y: textRect.origin.y + textRect.size.height + descender + 2))
        contextRef.closePath()
        contextRef.strokePath()
    }
}
